package com.M10.BE.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.M10.BE.R;
import com.M10.BE.inventory.UncheckedInveDetailActivity;
import com.fn.useries.model.Inventory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/8/2.
 */

public class InveUnCheckListAdapter extends RecyclerView.Adapter<InveUnCheckListAdapter.MasonryView> {
    private List<Inventory> inventories;
    private Context ctx;

    public InveUnCheckListAdapter(ArrayList<Inventory> inventories, Context context) {
        this.inventories = inventories;
        ctx = context;
    }

    @Override
    public InveUnCheckListAdapter.MasonryView onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_inventory_uncheck, parent, false);
        return new InveUnCheckListAdapter.MasonryView(view);
    }

    @Override
    public void onBindViewHolder(InveUnCheckListAdapter.MasonryView holder, final int position) {
        holder.orderNo.setText(inventories.get(position).getOrderNO());
        holder.dept.setText(inventories.get(position).getOrgName());
        holder.totalAssets.setText(inventories.get(position).getQueryCount());
        holder.time.setText(inventories.get(position).getJudgeDate());
//        if (inventories.get(position).getCheckNum().equals("1")) {
//            holder.num.setTextColor(Color.parseColor("#FAF43009"));
//        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ctx, UncheckedInveDetailActivity.class);
                intent.putExtra("inventoryId", inventories.get(position).getId());
                ctx.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return inventories.size();
    }

    public static class MasonryView extends RecyclerView.ViewHolder {
        TextView orderNo;
        TextView dept;
        TextView totalAssets;
        TextView time;

        public MasonryView(View itemView) {
            super(itemView);
            orderNo = (TextView) itemView.findViewById(R.id.inve_oderno);
            dept = (TextView) itemView.findViewById(R.id.inve_dept);
            totalAssets = (TextView) itemView.findViewById(R.id.inve_totalassets);
            time = (TextView) itemView.findViewById(R.id.inve_time);
        }

    }
}
